﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace Slf.Samples.ExtendingFormattableLoggerBase
{
  /// <summary>
  /// A simple formatter that returns an XML representation of a given
  /// <see cref="LogItem"/>.
  /// </summary>
  public class XmlFormatter : ILogItemFormatter
  {
    private readonly XmlSerializer serializer = new XmlSerializer(typeof (LogItem));

    /// <summary>
    /// Creates a string representation of a given <see cref="LogItem"/>.
    /// </summary>
    /// <param name="item">The item to be processed.</param>
    /// <returns>A string representation of the submitted
    /// <paramref name="item"/>.</returns>
    public string FormatItem(LogItem item)
    {
      StringWriter writer = new StringWriter();
      serializer.Serialize(writer, item);
      return writer.ToString();
    }
  }
}